package com.example.demo.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.Dto.AddProductDto;
import com.example.demo.Dto.ListProductsDto;

import com.example.demo.Dto.SearchProductsDto;
import com.example.demo.VO.ProductInfoVo;
import com.example.demo.po.ProCateRel;
import com.example.demo.po.Product;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;
import java.util.List;

@Mapper
public interface GoodsMapper  extends BaseMapper<Product> {
    @Select("select * from product,\n" +
            "        (select category_name from category,\n" +
            "            (select category_id from product_category_relation where product_id=#{productId})  a\n" +
            "            where category.id=a.category_id) as b\n" +
            "            where id=#{productId};")
    ProductInfoVo getgoods(@Param("productId") long productId);
@Select("select product.* from product,\n" +
        "    (select product_id from product_category_relation ,\n" +
        "        (select id from category where category_name=#{ListProductsDto.categoryName}) as a\n" +
        "     where a.id=product_category_relation.category_id) as b\n" +
        "where b.product_id=product.id\n")
List<ProductInfoVo> list(@Param("ListProductsDto") ListProductsDto ListProductsDto);

List<ProductInfoVo> searchlights(@Param("searchProductsDto") SearchProductsDto searchProductsDto);
@Update("UPDATE product set stock=stock+#{addProductDto.addStock} where id=#{addProductDto.productId};")
    int add(@Param("addProductDto") AddProductDto addProductDto);



    Integer batch1(@Param("product") Product  product);

    Integer batch(@Param("product") ArrayList<Object> objects);

    Integer update(@Param("product") Product bean);
@Select("select id from category where category_name=#{category};")
    Long selectcategoryId(@Param("category") String category);

    Integer init( @Param("objects") ArrayList<ProCateRel> objects);
}
